﻿/**《Version、Commend Info》************************************************
 * FileName：TestRegisterAttribute
 * Function：
 * Description：
 * Version：V2.0.1
 * ------------------------------------------
 * CreateTime：2021/10/28 8:42:50
 * Author：赵旋
 * Email： 1192508693@qq.com
 * ------------------------------------------
 * UserName：   DanyMoon
 * MachineName：DESKTOP-S78OH2C
 * ========================================================================= 
 * 
 * Modifyier：	
 * ModifyTime：	
 * Description：	
 ***************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.Base.Test
{
    [AttributeUsage(AttributeTargets.Class)]
    public class TestRegisterAttribute: Attribute
    {
        private TestClsEnum.TestClsEnumX _TestCls;
        public TestClsEnum.TestClsEnumX TestCls { get { return this._TestCls; } }

        private string _AssemblyName;
        public string AssemblyName { get { return this._AssemblyName; } }

        private string _NameSpace;
        public string NameSpace { get { return this._NameSpace; } }

        public TestRegisterAttribute(TestClsEnum.TestClsEnumX testCls)
        {
            this._TestCls = testCls;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="testCls">测试分类</param>
        /// <param name="assemblyName">使用当前特性的程序集名称。程序集名称与默认命名空间查看：右键项目👉选择属性👉应用程序选项卡即可查看</param>
        /// <param name="namespaceofRegesteredClass">使用当前特性的类所在的命名空间。注意：使用当前特性的类所在的命名空间 一般与程序集名称一致。</param>
        public TestRegisterAttribute(TestClsEnum.TestClsEnumX testCls, string assemblyName, string namespaceofRegesteredClass = "")
        {
            this._TestCls = testCls;
            this._AssemblyName = assemblyName;
            this._NameSpace = namespaceofRegesteredClass;
            if (!string.IsNullOrEmpty(namespaceofRegesteredClass))
            {
                this._NameSpace = namespaceofRegesteredClass;
            }
        }
    }

    public class TestClsEnum
    {
        public enum TestClsEnumX
        {
            Example = 0,
            LY,
            CHH,
            HX,
            YHA,
            HJ,
            LJH,
            WHT,
            YBW,
        }

        private static readonly Dictionary<TestClsEnumX, string> _Names = new Dictionary<TestClsEnumX, string>
        {
            { TestClsEnumX.Example, "示例"},
            { TestClsEnumX.LY, "小助手"},
            { TestClsEnumX.CHH, "陈欢欢"},
            { TestClsEnumX.HX, "胡鑫"},
            { TestClsEnumX.YHA, "游浩安"},
            { TestClsEnumX.HJ, "何佳"},
            { TestClsEnumX.LJH, "李嘉宏"},
            { TestClsEnumX.WHT, "吴海涛"},
            { TestClsEnumX.YBW, "尹博文"},
        };

        public static TestClsEnumX[] GetAllKeys()
        {
            return _Names.Keys.ToArray();
        }

        public static List<KeyValuePair<TestClsEnumX, string>> GetAllList()
        {
            return _Names.ToList();
        }

        public static string GetName(TestClsEnumX key)
        {
            return _Names[key];
        }

        public static TestClsEnumX GetKey(string keyName)
        {
            if (string.IsNullOrEmpty(keyName))
            {
                return TestClsEnumX.Example;
            }
            var names = Enum.GetNames(typeof(TestClsEnumX));
            if (!names.Contains(keyName))
            {
                return TestClsEnumX.Example;
            }

            TestClsEnumX testCls = TestClsEnumX.Example;
            Enum.TryParse<TestClsEnumX>(keyName, out testCls);
            return testCls;
        }
    }
}